#include "StdAfx.h"
#include "handler_test.h"
using fly::jld::test::handler_test;



TEST_F(handler_test, rtt_from_login)
{

	RoundTripTime rtt;

	//------------0-----------
	rtt.set_is_proof(true);
	encode_header(rtt, RTT);
	EXPECT_TRUE(handle_header());

	EXPECT_TRUE(handle_body());

	decode_header();
	EXPECT_EQ(RTT, header_.pid());

	decode_body(rtt);

	EXPECT_EQ(true, rtt.is_proof());
	EXPECT_LT(0, rtt.srv_time());

	//------------1-------------

	rtt.set_cln_time(timestamp->cur_mill_sec());

	encode_header(rtt, RTT);

	EXPECT_TRUE(handle_header());

	encode_body(rtt);

	EXPECT_TRUE(handle_body());

	decode_header();
	EXPECT_EQ(RTT, header_.pid());

	decode_body(rtt);

	EXPECT_EQ(true, rtt.is_proof());
	EXPECT_LT(0, rtt.srv_time());

	//------------2-------------
}

TEST_F(handler_test, rtt_un_proof)
{
	RoundTripTime rtt;

	//------------0-----------
	rtt.set_is_proof(true);
	encode_header(rtt, RTT);
	EXPECT_TRUE(handle_header());

	EXPECT_TRUE(handle_body());

	decode_header();
	EXPECT_EQ(RTT, header_.pid());

	decode_body(rtt);

	EXPECT_LT(0, rtt.srv_time());

	//------------1-------------

	while (rtt.is_proof())
	{
		rtt.set_cln_time(timestamp->cur_mill_sec());

		encode_header(rtt, RTT);

		EXPECT_TRUE(handle_header());

		encode_body(rtt);

		EXPECT_TRUE(handle_body());

		decode_header();
		EXPECT_EQ(RTT, header_.pid());

		decode_body(rtt);

		EXPECT_LT(0, rtt.srv_time());
	}

	EXPECT_FALSE(rtt.is_proof());
	EXPECT_LE(0, rtt.rtt());
}